<!doctype html>
	<?php
		if(session_get(UserEnum::USER_INFO_USER_ID)){
			echo "<script>document.location.href='/';</script>";
		}
	?>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>央票通</title>
	<link rel="stylesheet" href="./resource/css/login.css">
</head>
<body>
<!-- head -->
<div class="head">
	<div class="main">
		<div class="logo">
			<a href="/index.php"><img src="./resource/img/logo.png" alt=""></a>
		</div>
		<div class="ul">
			<ul>
				<li class="active"><a href="/index.php">首页</a></li>
				<li class="app"><a href="javascript:;">APP下载</a></li>
			</ul>
		</div>
	</div>
</div>
<!-- cont -->
<div class="cont-login">
	<div class="main">
		<div class="login-container">
			<div class="title">
				<div class="left">登录用户</div>
				<div class="right">还没账号？<a href="/register">立即注册</a></div>
			</div>
			<div class="form form-login">
				<form action="/verify_login" method="post" onsubmit = "return check_all()">
					<div class="form-group icon-tel">
						@if(!empty($_COOKIE['name']))
							<input type="text" class="form-control" placeholder="手机号/用户名" name="username" id='username' onblur="check_username()" value=<?php echo $_COOKIE['name']?>>
						@else
							<input type="text" class="form-control" placeholder="手机号/用户名" name="username" id='username' onblur="check_username()">
						@endif
						<br>
						<span id="t_username" class="span"></span>
					</div>
					<div class="form-group icon-pass">
						<input type="password" class="form-control" placeholder="密码" name="password" id='pwd' onblur="check_pwd()">
						<br>
						<span id="t_pwd" class="span"></span>
					</div>
					<div class="form-group">
						<input type="checkbox"  name="remember"/> 记住用户名
						<a href="/user_retrieve_pwd_one">忘记密码？</a>
					</div>
					<input type="submit"  value="登陆" class="btn btn-login" id="sub">
				</form>
				<div class="img-box"><img src="./resource/img/login_l.png" alt=""></div>
			</div>
		</div>
	</div>
</div>
<div class="footer">
	Copyright © 2016 央票通（中企汇科技（北京）股份有限公司） 版权所有；市场有风险，投资需谨慎，营造合法、诚信借贷环境。苏ICP备15005239号-2
</div>
</body>
</html>
<script>
	//验证用户名
	function check_username(){
		var username = document.getElementById('username').value;
		var status = false
		if(username){
			var ajax = new XMLHttpRequest();
			ajax.onreadystatechange = function () {
				if (ajax.readyState == 4) {
					if (ajax.responseText == 0) {
						document.getElementById("t_username").innerHTML = "用户名不存在";
					} else {
						document.getElementById("t_username").innerHTML = "";
						status = true
					}
				}
			}
			//与服务器建立连接
			ajax.open('post', '/js_verify_login', false);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//处理请求
			ajax.send('username=' + username);
			return status
		}else{
			document.getElementById('t_username').innerHTML = "用户名不能为空";
			return false
		}
	}
	//验证密码
	function check_pwd()
	{
		var pwd	= document.getElementById('pwd').value
		if(pwd){
			document.getElementById('t_pwd').innerHTML = '';
			return true;
		}else{
			document.getElementById('t_pwd').innerHTML = '密码不能为空';
			return false;
		}
	}

	function check_all()
	{
		var pwd	= document.getElementById('pwd').value
		var username = document.getElementById('username').value;
		var status = false;
		if(pwd) {
			document.getElementById('t_pwd').innerHTML = '';
			if (username) {
				var ajax = new XMLHttpRequest();
				ajax.onreadystatechange = function () {
					if (ajax.readyState == 4) {
						if (ajax.responseText == 0) {
							document.getElementById("t_pwd").innerHTML = '用户名或密码密码有误';
						} else {
							document.getElementById("t_pwd").innerHTML = '';
							status = true;
						}

					}
				}
				//与服务器建立连接
				ajax.open('post', '/js_verify_login', false);
				ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				ajax.send('username=' + username + "&pwd=" + pwd);
				return status;
			}
		}
		return (check_username()&&check_pwd())
	}
</script>